//
//  GetStoryCardPopUpViewController.m
//  KidReading
//
//  Created by YangShuai on 16/11/18.
//  Copyright © 2016年 刘赞黄Telen. All rights reserved.
//

#import "GetStoryCardPopUpViewController.h"
#import "ConstDefine.h"
@interface GetStoryCardPopUpViewController ()

@end

@implementation GetStoryCardPopUpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEmpty)];
    UISwipeGestureRecognizer* swipeGes = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(undo)];
    swipeGes.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:swipeGes];
    [self.view addGestureRecognizer:tap];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}

-(void)undo{
    
}

- (void)tapEmpty
{
    [UIView animateWithDuration:0.3f animations:^{
        self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
        self.view.alpha = 0;
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        [self willMoveToParentViewController:nil];
        [self removeFromParentViewController];
    }];
}

- (void)showBackGroundColor{
    [UIView animateWithDuration:0.3f animations:^{
        self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
    } completion:^(BOOL finished) {
        self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
    }];
}

- (void)unShowAndRemove{
    [self tapEmpty];
}
//
+ (GetStoryCardPopUpViewController*)showPopUpViewToActivityVC:(UIViewController*)parentVC StoryCardName:(NSString*)storyCardName CardCount:(NSInteger)cardCount StoryCardimage:(UIImage*)storyCardimage{
    GetStoryCardPopUpViewController* popUpVC = [[GetStoryCardPopUpViewController alloc] init];
    [parentVC addChildViewController:popUpVC];
    [parentVC.view addSubview:popUpVC.view];
    [popUpVC didMoveToParentViewController:parentVC];
    [popUpVC showBackGroundColor];
    //
    [popUpVC layoutViewsWithStoryCardName:storyCardName StoryCardImage:storyCardimage CardConut:cardCount];
    return popUpVC;
}

-(void)layoutViewsWithStoryCardName:(NSString*)storyCardName StoryCardImage:(UIImage*)storyCardImage CardConut:(NSInteger)cardCount{
    UIView* backView = [[UIView alloc] init];
    backView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:backView];
    [backView JRMAS_makeConstraints:^(JRMASConstraintMaker *make) {
        make.size.JRMAS_equalTo(CGSizeMake(668 / ratio_w, 620 / ratio_w));
        make.center.JRMAS_equalTo(0);
    }];//
    //
    UIImageView* storyCardImageView = [[UIImageView alloc] init];
    storyCardImageView.image = storyCardImage;
    [backView addSubview:storyCardImageView];
    [storyCardImageView JRMAS_makeConstraints:^(JRMASConstraintMaker *make) {
        make.top.JRMAS_equalTo(0);
        make.centerX.JRMAS_equalTo(0);
        make.size.JRMAS_equalTo(CGSizeMake(290 / ratio_w, 385 / ratio_w));
    }];
    //
    UILabel* name_countLabel = [[UILabel alloc] init];
    name_countLabel.text = [NSString stringWithFormat:@"您获得了“%@”的碎片 x%@",storyCardName,@(cardCount)];
    name_countLabel.textColor = [UIColor colorWithHexString:@"#FFDF31"];
    name_countLabel.font = [UIFont systemFontOfSize:36 / ratio_w];
    [backView addSubview:name_countLabel];
    [name_countLabel JRMAS_makeConstraints:^(JRMASConstraintMaker *make) {
        make.centerX.JRMAS_equalTo(0);
        make.top.JRMAS_equalTo(storyCardImageView.JRMAS_bottom).offset(25 / ratio_w);
    }];
    //
    UILabel* viewDetailLabel = [[UILabel alloc] init];
    viewDetailLabel.text = @"请在卡牌栏目内查看详情";
    viewDetailLabel.font = [UIFont systemFontOfSize:24 / ratio_w];
    viewDetailLabel.textColor = [UIColor colorWithHexString:@"#F0F1F5"];
    [backView addSubview:viewDetailLabel];
    [viewDetailLabel JRMAS_makeConstraints:^(JRMASConstraintMaker *make) {
        make.top.JRMAS_equalTo(name_countLabel.JRMAS_bottom).offset(15 / ratio_w);
        make.centerX.JRMAS_equalTo(0);
    }];
    //
    UIButton* sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [sureButton addTouchScaleTransitions];
    sureButton.adjustsImageWhenHighlighted = NO;
    [sureButton setTitle:@"知道了" forState:UIControlStateNormal];
    [sureButton setTitleColor:[UIColor colorWithHexString:@"#F8E71C"] forState:UIControlStateNormal];
    [sureButton addTarget:self action:@selector(unShowAndRemove) forControlEvents:UIControlEventTouchUpInside];
    sureButton.titleLabel.font = [UIFont systemFontOfSize:24 / ratio_w];
    sureButton.layer.borderColor = [UIColor colorWithHexString:@"#F8E71C"].CGColor;
    sureButton.layer.borderWidth = 1;
    sureButton.layer.cornerRadius = 25 / ratio_w;
    sureButton.layer.masksToBounds = YES;
    [backView addSubview:sureButton];
    [sureButton JRMAS_makeConstraints:^(JRMASConstraintMaker *make) {
        make.size.JRMAS_equalTo(CGSizeMake(240 / ratio_w, 50 / ratio_w));
        make.centerX.JRMAS_equalTo(0);
        make.top.JRMAS_equalTo(viewDetailLabel.JRMAS_bottom).offset(55 / ratio_w);
    }];
    //
    [backView layoutIfNeeded];
    YSFallDownEmitterView* fullDownView = [YSFallDownEmitterView showFallDownSpatterViewFrame:backView.bounds FallImageArray:[self getFallDownImageArray]];
    [backView addSubview:fullDownView];
    [DataProcess do_Main:^{
        [UIView animateWithDuration:0.3 animations:^{
            fullDownView.alpha = 0;
        }completion:^(BOOL finished) {
            [fullDownView removeFromSuperview];
        }];
    } delay:1];
}
-(NSArray*)getFallDownImageArray{
    NSMutableArray* imageArray = [NSMutableArray new];
    [imageArray addObject:[UIImage imageNamed:@"Popups_bg_bluepurple.png"]];
    [imageArray addObject:[UIImage imageNamed:@"Popups_bg_triangle_blue.png"]];
    [imageArray addObject:[UIImage imageNamed:@"Popups_bg_triangle_brown.png"]];
    [imageArray addObject:[UIImage imageNamed:@"Popups_bg_triangle_glaucous.png"]];
    [imageArray addObject:[UIImage imageNamed:@"Popups_bg_triangle_green.png"]];
    [imageArray addObject:[UIImage imageNamed:@"Popups_bg_triangle_pink.png"]];
    [imageArray addObject:[UIImage imageNamed:@"Popups_bg_triangle_purple.png"]];
    [imageArray addObject:[UIImage imageNamed:@"Popups_bg_triangle_red.png"]];
    [imageArray addObject:[UIImage imageNamed:@"Popups_bg_triangle_yellow.png"]];
    return imageArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
